function Qim = function_Q(i, m, J, S,p)
    % 返回Q i m
    % 建议主程序把 整个程序共有的变量 p, J 设置为Global变量
    % global p J
    %fac = @factorial; % 阶乘简写
    
    for ii = 1 : A(1)
        pie = PIE(ii, :);
        cell2 = 1;
        for jj = 1 : J % 连乘
            %cell = fac(ss(jj))/(fac(pie(jj))*fac(ss(jj)-pie(jj)));
            %算组合有专门的函数，cell可以不手动算
            cell = nchoosek(ss(jj),pie(jj));
            cell = cell * p(jj)^pie(jj) * (1-p(jj))^(ss(jj)-pie(jj));
            cell2 = cell2 * cell;
        end
        Qim = Qim + cell2;
    end
    
  


